#pragma once
#include <vector>
#include <istream>

namespace XRwy {
    
    class TransformationReader {
    public:
        TransformationReader(std::istream * stream) { init(stream); }
        TransformationReader(const std::string file_path) {
            std::ifstream fin(file_path, std::ios::in);
            init(&fin);
        }

        void init(std::istream * stream) {
            float tmp;
            while ((*stream) >> tmp) {
                this->values.push_back(tmp);
            }
            assert(values.size() % 16 == 0);
        }

        size_t size() const {
            return values.size() / 16;
        }

        Eigen::Affine3f get_trans(int idx) const {
            Eigen::Matrix4f tmp;
            for (int i = 0; i < 4; ++i)
                for (int j = 0; j < 4; ++j)
                    tmp(i, j) = values[idx * 16 + i * 4 + j];

            Eigen::Affine3f aff;
            aff.matrix() = tmp;
                    
            return std::move(aff);
        }
    private:
        std::vector<float> values;
    };
}
